﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using com.subb.WebInformation;
using WebEntities;
using com.subb.ProductInformation;
using com.subb.WebFramework;
using WebsiteUI.ActionFilters;

namespace WebsiteUI.Controllers
{
    /// <summary>
    /// 在这里放公共的局部视图，用户控件
    /// </summary>
    public class PublicPartialViewController : Controller
    {
        //
        // GET: /PublicPartialView/
        /// <summary>
        /// 专家动态滚动
        /// </summary>
        /// <param name="limit"></param>
        /// <returns></returns>
        //[OutputCache(Duration = 3 * 60 * 60, VaryByParam = "none")]
        //[OutputCache(CacheProfile = "Cache15Mins", VaryByParam = "*")]
        public ActionResult GetExpertRandom(int limit = 10)
        {
            WI_ExpertsDAL dal = new WI_ExpertsDAL();
            List<WI_Experts> list = dal.GetRandomExperts(limit);
            return PartialView(list);
        }

        /// <summary>
        /// 获取最新产品列表
        /// </summary>
        /// <param name="limit"></param>
        /// <returns></returns>
        //[OutputCache(Duration = 3 * 60 * 60, VaryByParam = "none")]
        //[OutputCache(CacheProfile = "Cache15Mins", VaryByParam = "*")]
        public ActionResult GetLastestProduct(int limit = 8)
        {
            PP_ProductDAL dal = new PP_ProductDAL();
            List<PP_Product> list = dal.GetUiLastestProduct(limit);
            return PartialView(list);
        }

        /// <summary>
        /// 圆圈菜单视图
        /// </summary>
        /// <param name="id">新闻目录ID</param>
        /// <param name="miId">菜单项ID</param>
        // [CtrlActionOutputCache("Cache1Hour", VaryByParam = "*")]
        public ActionResult CircleMenu(int? miId, int? id)
        {
            FW_MenuItemDAL midal = new FW_MenuItemDAL();
            List<FW_MenuItem> mitemList = new List<FW_MenuItem>();
            FW_MenuDAL mdal = new FW_MenuDAL();
            if (miId.HasValue)
            {
                //产品页面和专家信息页面
                int itemId = miId ?? 100;
                ViewBag.MuItemID = itemId;
                FW_MenuItem mitem = midal.GetMenuItem(itemId);
                if (mitem != null)
                {
                    int menuId = mitem.MenuID ?? 0;
                    mitemList = midal.GetMenuItemsByMenuID(menuId);
                    FW_Menu menu = mdal.GetMenu(menuId);
                    if (menu != null)
                    {
                        ViewBag.MenuName = menu.MenuName;
                    }
                }
            }
            else
            {
                //新闻页面
                int cataId = id ?? 100;
                WI_NewsCataDAL ncdal = new WI_NewsCataDAL();
                WI_NewsCata ncata = ncdal.GetNewsCata(cataId);
                if (ncata != null)
                {
                    int itemId = ncata.MenuItemID ?? 0;
                    ViewBag.MuItemID = itemId;
                    FW_MenuItem mitem = midal.GetMenuItem(itemId);
                    if (mitem != null)
                    {
                        int menuId = mitem.MenuID ?? 0;
                        mitemList = midal.GetMenuItemsByMenuID(menuId);
                        FW_Menu menu = mdal.GetMenu(menuId);
                        if (menu != null)
                        {
                            ViewBag.MenuName = menu.MenuName;
                        }
                    }
                }
            }
            return PartialView(mitemList);
        }

        /// <summary>
        /// 页面当前路径视图
        /// </summary>
        /// <param name="id">新闻目录ID</param>
        /// <param name="miId">菜单项ID</param>
        /// <returns></returns>
        public ActionResult PageCurrentPath(int? id, int? miId)
        {
            string pageline=string.Empty;
            FW_MenuItemDAL midal = new FW_MenuItemDAL();
            FW_MenuDAL mdal = new FW_MenuDAL();
            if (miId.HasValue)
            {
                //产品页面和专家信息页面
                int itemId = miId ?? 100;
                FW_MenuItem mitem = midal.GetMenuItem(itemId);
                if (mitem != null)
                {
                    int menuId = mitem.MenuID ?? 0;
                    FW_Menu menu = mdal.GetMenu(menuId);
                    if (menu != null)
                    {
                        pageline += " > <a href='" + menu.MenuUrl + "'>" + menu.MenuName + "</a>";
                    }
                    pageline += " > <a href='" + mitem.ItemUrl + "'>" + mitem.ItemName + "</a>";
                }
            }
            else
            {
                //新闻列表和新闻详细页面
                int cataId = id ?? 100;
                WI_NewsCataDAL ncdal = new WI_NewsCataDAL();
                WI_NewsCata ncata = ncdal.GetNewsCata(cataId);
                if (ncata != null)
                {
                    int itemId = ncata.MenuItemID ?? 0;
                    FW_MenuItem mitem = midal.GetMenuItem(itemId);
                    if (mitem != null)
                    {
                        int menuId = mitem.MenuID ?? 0;
                        FW_Menu menu = mdal.GetMenu(menuId);
                        if (menu != null)
                        {
                            pageline += " > <a href='" + menu.MenuUrl + "'>" + menu.MenuName + "</a>";
                        }

                        if (ncata.ParentCataID.HasValue)
                        {
                            //一级目录菜单链接
                            pageline += " > <a href='" + mitem.ItemUrl + "'>" + mitem.ItemName + "</a>";
                            //二级目录菜单链接
                            pageline += " > <a href='/list/index/" + ncata.CataID + "'>" + ncata.CataName + "</a>";
                        }
                        else
                        {
                            //一级新闻目录，直接获取菜单链接
                            pageline += " > <a href='" + mitem.ItemUrl + "'>" + mitem.ItemName + "</a>";
                        }
                    }
                }
            }
            ViewBag.PageLine = pageline;
            return PartialView();
        }

        /// <summary>
        /// 详细页面- 左下角东西 联系我们
        /// </summary>
        /// <returns></returns>
        public ActionResult Contact()
        {
            return PartialView();
        }
        /// <summary>
        /// 轮播广告
        /// </summary>
        /// <returns></returns>
      // [OutputCache(Duration = 1800, VaryByParam = "none")]
        public ActionResult ADScroll(int suiteId=100)
        {
            WI_AdvItemDAL dal = new WI_AdvItemDAL();
            List<WI_AdvItem> list = dal.GetAllAdvItemsByUI(suiteId);
            return PartialView(list);
        }

        /// <summary>
        /// banner广告
        /// </summary>
        /// <returns></returns>
        // [OutputCache(Duration = 1800, VaryByParam = "none")]
        public ActionResult ADBanner(int suiteId = 101)
        {
            WI_AdvItemDAL dal = new WI_AdvItemDAL();
            List<WI_AdvItem> list = dal.GetAllAdvItemsByUI(suiteId);
            return PartialView(list);
        }

    }
}
